<!--选举管理-->
<template>
  <div>
    <Row class="search-info-style">
      <Col span="6">
        <span>选举标题：</span>
        <Input v-model="searchInfo.title" placeholder="选举标题" style="width:70%" />
      </Col>
      <Col span="6">
        <span>选举年份：</span>
        <DatePicker type="year" placeholder="届数" v-model="searchInfo.year" style="width: 70%"></DatePicker>
      </Col>
      <Col style="float:right" pull="1">
        <!-- <Button class="new-btn-sty" @click="add({})"><Icon type="md-add" /> 添加</Button> -->
        <Button class="new-btn-sty" @click="findtime()"><Icon type="ios-search" />搜索</Button>
        <Button class="new-btn-sty" @click="add()"><Icon type="md-browsers" />添加</Button>
      </Col>
      <!-- <Col span="2" style="float:right" pull="1">
          <Button class="new-btn-sty" @click="findtime()"><Icon type="ios-search" /> 搜索</Button>
      </Col> -->
    </Row>
    <Table border :columns="columns1" :data="data1"></Table>
    <Row v-if="loadData == true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
    <Page class="page_style" :total="totalnum" :current="currentPageNo"
          :page-size="currentPageSize" @on-change="changePageNo" show-total  show-sizer @on-page-size-change="size"/>
<!--    选举管理录入修改模态框-->
    <Modal v-model="modalEdit" title="选举公告信息表" width="700" cancel-text="关闭"
           @on-ok="ok111(paramData)" @on-cancel="modalEdit=false" ok-text="确定">
      <Form :model="paramData" >
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">选举标题:</Col>
          <Col span="12" offset="1">
            <Input v-model="paramData.title"></Input>
          </Col>
        </Row>
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">选举地点:</Col>
          <Col span="12" offset="1">
            <Input v-model="paramData.address"></Input>
          </Col>
        </Row>
        <Row  class="item1">
          <Col span="5" style="text-align: right" class="">选举方式:</Col>
          <Col span="12" offset="1">
            <Select v-model="paramData.mode" placeholder="请选择公示类型">
              <Option value="直接选举">直接选举（全体选民选举）</Option>
              <Option value="间接选举">间接选举（选民代表选举）</Option>
            </Select>
          </Col>
        </Row>
        <Row class="item1" v-if="parameter == '1'">
          <Col span="5" style="text-align: right" class="">选举年份:</Col>
          <Col span="12" offset="1">
            <DatePicker type="year" placeholder="届数" v-model="paramData.year"></DatePicker><span>届</span>
          </Col>
        </Row>
        <Row class="item1" v-if="parameter == '2'">
          <Col span="5" style="text-align: right" class="">选举年份:</Col>
          <Col span="12" offset="1">
            <DatePicker disabled type="year" placeholder="届数" v-model="paramData.year"></DatePicker><span>届</span>
          </Col>
        </Row>
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">公示日期（始）:</Col>
          <Col span="12" offset="1">
            <DatePicker type="date" placeholder="选择日期" v-model="paramData.start_time"></DatePicker>
          </Col>
        </Row>
        <Row  class="item1">
          <Col span="5" style="text-align: right" class="">公示日期（终）:</Col>
          <Col span="12" offset="1">
            <DatePicker type="date" placeholder="选择日期" v-model="paramData.end_time"></DatePicker>
          </Col>
        </Row>
      </Form>
    </Modal>
    <Modal v-model="modalEdit2" title="选举公告信息表" width="700" cancel-text="关闭"
           @on-ok="ok222(paramData)" @on-cancel="modalEdit=false" ok-text="确定">
      <Form :model="paramData" >
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">选举标题:</Col>
          <Col span="12" offset="1">
            <Input disabled v-model="paramData.title"></Input>
          </Col>
        </Row>
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">选举地点:</Col>
          <Col span="12" offset="1">
            <Input disabled v-model="paramData.address"></Input>
          </Col>
        </Row>
        <Row  class="item1">
          <Col span="5" style="text-align: right" class="">选举方式:</Col>
          <Col span="12" offset="1">
            <Select disabled v-model="paramData.mode" placeholder="请选择公示类型">
              <Option value="直接选举">直接选举（全体选民选举）</Option>
              <Option value="间接选举">间接选举（选民代表选举）</Option>
            </Select>
          </Col>
        </Row>
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">选举年份:</Col>
          <Col span="12" offset="1">
            <DatePicker disabled type="year" placeholder="届数" v-model="paramData.year"></DatePicker><span>届</span>
          </Col>
        </Row>
        <Row class="item1">
          <Col span="5" style="text-align: right" class="">公示日期（始）:</Col>
          <Col span="12" offset="1">
            <DatePicker disabled type="date" placeholder="选择日期" v-model="paramData.start_time"></DatePicker>
          </Col>
        </Row>
        <Row  class="item1">
          <Col span="5" style="text-align: right" class="">公示日期（终）:</Col>
          <Col span="12" offset="1">
            <DatePicker disabled type="date" placeholder="选择日期" v-model="paramData.end_time"></DatePicker>
          </Col>
        </Row>
      </Form>
    </Modal>
    <Modal v-model="modalEdit3" title="再次确认" width="700" cancel-text="关闭"
           @on-ok="ok333(paramData)" @on-cancel="modalEdit3=false" ok-text="确定">
      <div style="color: red; font-size: 3rem; text-align: center;">确定删除此届选举吗！</div>
    </Modal>

  </div>
</template>
<script>
import { getElectionList, createElection, date2str, deleteElection, getElectionDetails } from '@/api/eventlist'
export default {
  data () {
    return {
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      searchInfo: {},
      paramData: {},
      param: {},
      loadData: true,
      modalEdit: false,
      modalEdit2: false,
      modalEdit3: false,
      company_code: this.$store.state.user.severUserInfo.company_code,
      parameter: '1',
      data1: [],
      columns1: [
        { title: '序号', type: 'index', width: 80, align: 'center' },
        { title: '选举标题', key: 'title', width: 300, align: 'center' },
        { title: '选举年份', key: 'year', width: 100, align: 'center' },
        { title: '社会统一信用代码', key: 'succ', width: 300, align: 'center' },
        { title: '公示开始时间', key: 'start_time', width: 150, align: 'center' },
        { title: '公示结束时间', key: 'end_time', width: 150, align: 'center' },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          className: 'nopadding',
          minWidth: 200,
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: { type: 'error', size: 'small' },
                style: { marginRight: '5px', backgroundColor: '#18B0FF', borderColor: '#18B0FF' },
                on: {
                  click: () => {
                    this.downLoad(params.row)
                  }
                }
              }, '查看')
            )
              temp.push(
                h('Button', {
                  props: { type: 'primary', size: 'small' },
                  style: { marginRight: '5px', backgroundColor: '#598ED1', borderColor: '#598ED1' },
                  on: {
                    click: () => {
                      this.viewProcess(params.row)
                    }
                  }
                }, '编辑'),
                h('Button', {
                  props: { type: 'error', size: 'small' },
                  style: { marginRight: '5px' },
                  on: {
                    click: () => {
                      this.remove(params.row)
                    }
                  }
                }, '删除')
              )
            return h('div', temp)
          }
        }
      ],
    }
  },
  methods: {
    init() {
      let params = {
        company_code: this.company_code,
        pageSize: this.currentPageSize,
        pageNo: this.currentPageNo,
        title: this.searchInfo.title,
        year: date2str(this.searchInfo.year)
      }
      getElectionList(params).then(res => {
        if (res.data.errcode === 0) {
          this.data1 = res.data.data.results
          this.loadData = false
          this.totalnum = res.data.data.totalRecord
        } else {
          this.$Notice.error({ title: '获取材料信息列表失败', desc: res.data.errmsg })
          this.loadData = false
        }
      })
    },
    add() {
      this.parameter = '1'
      this.modalEdit = true
    },
    ok111() {
      // 保存修改接口
      this.paramData.year = date2str(this.paramData.year)
      this.paramData.start_time = date2str(this.paramData.start_time)
      this.paramData.end_time = date2str(this.paramData.end_time)
      createElection(this.paramData).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '保存成功', desc: '' })
          this.paramData = {}
          this.init()
        } else {
          this.$Notice.error({ title: '保存失败', desc: res.data.errmsg })
          this.init()
        }
      })
    },
    viewProcess(item) {
      this.parameter = '2'
      this.modalEdit = true
      getElectionDetails(item).then(res => {
        if (res.data.errcode === 0) {
          this.paramData = res.data.data
        } else {
          this.$Notice.error({ title: '查询失败', desc: res.data.errmsg })
          this.init()
        }
      })
    },
    remove(item) {
      this.param = item
      this.modalEdit3 = true
    },
    downLoad(item) {
      this.modalEdit2 = true
      getElectionDetails(item).then(res => {
        if (res.data.errcode === 0) {
          this.paramData = res.data.data
        } else {
          this.$Notice.error({ title: '查询失败', desc: res.data.errmsg })
          this.init()
        }
      })
    },
    ok222(item) {
      this.modalEdit2 = false
      this.init()
    },
    ok333() {
      deleteElection(this.param).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '删除成功', desc: '' })
          this.init()
        } else {
          this.$Notice.error({ title: '查询失败！请重试', desc: res.data.errmsg })
          this.init()
        }
      })
    },
    findtime() {
      this.init()
    },
    size (pageSize) {
      this.currentPageSize = pageSize
      this.changePageNo()
    },
    changePageNo (pageNo) {
      this.currentPageNo = pageNo
      this.init(this.param)
    },
  },
  mounted() {
    this.init()
  }
}
</script>
<style>
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .search-info-style {
    margin: 10px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
</style>
